﻿package com.tvein.sanguo.swc.action.login
{
	//flash
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	//A3D
	//custom
	import com.tvein.sanguo.swc.common.SwcEvent;
	import com.tvein.sanguo.swc.common.MP3Click;
//
	public class LoginGame extends MovieClip
	{
		public static const NAME:String = "Login-Game";
		
		private var effectVol:int = 100;
		
		public function LoginGame()
		{
			stage?init(null):addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(evt:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			addEventListener(Event.REMOVED_FROM_STAGE, _onRemoved);
			stage.addEventListener(Event.RESIZE, _resizeUI);
			
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			btnEnter.addEventListener(MouseEvent.CLICK, onClick);
			
			mcFrame.reSize(400, 300);
			
			_resizeUI();
		}

		public function console(Type:String, params:Object):void
		{
			switch (Type)
			{
				case "setEffect":
					effectVol = params.Volume;
					break;
				case "setGameInfo":
					setGameInfo(params);
					break;
			}
		}
		
		private function setGameInfo(params:Object):void
		{
			txtStatement.htmlText = params[0].Value;
		}
		
		private function onClick(evt:MouseEvent):void
		{			
			var mp3Click:MP3Click = new MP3Click();
			mp3Click.playback(effectVol * .01);
			
			switch(evt.target.name)
			{
				case "btnEnter":
					dispatchEvent(new SwcEvent(NAME, ["-getRoleList"]));
					break;
			}
		}
		
		private function _onRemoved(evt:Event):void
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, _onRemoved);
			stage.removeEventListener(Event.RESIZE, _resizeUI);
			
			btnEnter.removeEventListener(MouseEvent.CLICK, onClick);
		}

		private function _resizeUI(evt:Event = null):void
		{
			this.x = (stage.stageWidth - this.width) * .5
			if ((stage.stageHeight - this.height) > 100)
			{
				this.y = (stage.stageHeight - this.height) * .5;
			}
			else
			{
				this.y = 50;
			}
		}
	}
}